package com.cpu.z80.register;

/**
 * This is the 16Bit Register Class!
 * @author kennux
 */

import java.util.BitSet;

public class Double8Bit {
    private byte r1;
    private byte r2;

    public Double8Bit() {
        r1 = 0;
        r2 = 0;
    }

    public void set8Bit(byte Value, int register) {
        if (register == 1) {
            r1 = Value;
        } else {
            r2 = Value;
        }
    }

    public byte get8Bit(int register) {
        if(register == 1) {
            return r1;
        } else {
            return r2;
        }
    }

    public void set16Bit(short value) {
        r1 = (byte)(value >> 8);
        r2 = (byte)(value & 0xFF);
    }

    public short get16Bit() {
        return (short)((r1 << 8 ) | r2);
    }

    public void add8Bit(byte val, int register) {
        if (register == 1) {
            r1 += val;
        } else {
            r2 += val;
        }
    }

    public void add16Bit(short val) {
       set16Bit((short)(get16Bit() + val));
    }

    public void sub8Bit(byte val, int register) {
        if (register == 1) {
            r1 -= val;
        } else {
            r2 -= val;
        }
    }

    public void sub16Bit(short val) {
       set16Bit((short)(get16Bit() - val));
    }

    public void setBit(int bitnumber) {
        set16Bit((short)(get16Bit() | (1 << bitnumber)));
    }

    public void clearBit(int bitnumber) {
        set16Bit((short)(get16Bit() & ~(1 << bitnumber)));
    }

    public boolean testBit( int bitnumber)
    {
      int mask = 1 << bitnumber;
      return (get16Bit() & mask) == mask; 
    }
}
